<script type="text/javascript" language="javascript" charset="utf-8">
$(".menu-wrap li").removeClass("active-link");
$(".menu-wrap #course").addClass("active");
$("#course #info").addClass("active-link");
$("#course #course_info a").addClass("active-link");
</script>
<div class="common-tit">
  <h2>课程列表</h2>
  <span>课程系统 > 课程列表 </span>
  <a class="add-staff" href="<%= new_admin_course_info_path %>">添加课程</a>
</div>
<div class="cur-list">
  <div class="cur-listbox clearfix">
    <div class="cur-ll clearfix">
      <div class="list-box">
        <div class="downbtn">
          <span data_id="all">请选择导师</span>
          <em></em>
        </div>
        <ul class="dropdown-menu">
          <li data_id="all">请选择导师</li>
          <% @teachers.each do |teacher| %>
            <li data_id="<%= teacher.name %>"><%= "#{teacher.name}" %></li>
          <%end%>
        </ul>
      </div>
      <div class="list-box">
        <div class="downbtn">
          <span data_id="all">请选择舞种</span>
          <em></em>
        </div>
        <ul class="dropdown-menu">
          <li data_id="all">请选择舞种</li>
          <% Company::DANCE_TYPE.each do |key, value| %>
            <li data_id="<%= key %>"><%= value %></li>
          <%end%>
        </ul>
      </div>
      <div class="list-box">
        <div class="downbtn">
          <span data_id="all">请选择销售类型</span>
          <em></em>
        </div>
        <ul class="dropdown-menu">
          <li data_id="all">请选择销售类型</li>
          <% CourseInfo::SALE_TYPE.each do |key,value| %>
            <li data_id="<%= key %>"><%= value %></li>
          <%end%>
        </ul>
      </div>
      <div class="list-box">
        <div class="downbtn">
          <span data_id="all">请选择课程类型</span>
          <em></em>
        </div>
        <ul class="dropdown-menu">
          <li data_id="all">请选择课程类型</li>
          <% CourseInfo::COURSE_TYPE.each do |key,value| %>
            <li data_id="<%= key %>"><%= value %></li>
          <%end%>
        </ul>
      </div>
      <div class="list-box">
        <div class="downbtn">
          <span data_id="all">请选择授课对象</span>
          <em></em>
        </div>
        <ul class="dropdown-menu">
          <li data_id="all">请选择授课对象</li>
            <% Company::AGE_GROUP.each do |key, value| %>
              <li data_id="<%= key %>"><%= value %></li>
            <%end%>
        </ul>
      </div>
      <div class="list-box l-last">
        <div class="downbtn">
          <span data_id="all">请选择课程状态</span>
          <em></em>
        </div>
        <ul class="dropdown-menu">
          <li data_id="all">请选择课程状态</li>
          <% CourseInfo::COURSE_STATUS.each do |key,value| %>
            <li data_id="<%= key %>"><%= value %></li>
          <%end%>
        </ul>
      </div>
    </div>
  </div>
  <div class="curlist-con">
    <div class="scrollbox">
      <table>
        <thead>
          <tr>
            <th class="curl-name">课程名称</th>
            <th class="curl-type">课程类型</th>
            <th class="curl-pos">导师</th>
            <th class="curl-dance">舞种</th>
            <th class="curl-stu">授课对象</th>
            <th class="curl-course">消费类型</th>
            <th class="curl-state">状态</th>
            <th class="curl-operation">操作</th>
          </tr>
        </thead>
        <tbody>
          <% @course_infos.each do |course_info| %>
          <tr>
            <td><%= course_info.name %></td>
            <td><%= course_info.course_type %></td>
            <td><%= course_info.teacher.name %></td>
            <td><%= course_info.dance_type %></td>
            <td><%= course_info.age_group %></td>
            <% if course_info.paying_ways.present? %>
            <td><%= course_info.paying_ways.size > 1 ? "#{course_info.paying_ways.first.pay_type} 等" : "#{course_info.paying_ways.first.pay_type}" %></td>
            <%else%>
              <td>-</td>
            <%end%>
            <td><%= course_info.status %></td>
            <td class="curl-operation">
              <span>[</span>
              <em><%= link_to "查看详情", admin_course_info_path(course_info) %></em>
              <span>]</span>
            </td>
          </tr>
          <%end%>
        </tbody>
      </table>
      <div class="apple_pagination" >
        <%= paginate @course_infos, :container => false %>
      </div>
    </div>
  </div>
</div>

<script src="/assets/js/common.js"></script>
<script type="text/javascript">
  $(".cur-ll .list-box li").on("click", function() {
    $(this).parent().parent().find("span").attr("data_id", $(this).attr("data_id"));
    transData();
  });
 function transData() {
  var transD = "";
  for (var i = 0; i < $(".cur-ll .list-box").length; i++) {
    switch(true) {
      case i == 0: transD += "teacher" + "=" + $($(".cur-ll .list-box")[i]).find("span").attr("data_id") + "&";break;
      case i == 1: transD += "dance_type" + "=" + $($(".cur-ll .list-box")[i]).find("span").attr("data_id") + "&";break;
      case i == 2: transD += "sale_type" + "=" + $($(".cur-ll .list-box")[i]).find("span").attr("data_id") + "&";break;
      case i == 3: transD += "course_type" + "=" + $($(".cur-ll .list-box")[i]).find("span").attr("data_id")+ "&";break;
      case i == 4: transD += "age_group" + "=" + $($(".cur-ll .list-box")[i]).find("span").attr("data_id") + "&";break;
      case i == 5: transD += "status" + "=" + $($(".cur-ll .list-box")[i]).find("span").attr("data_id");break;
    };
  };
  console.log(transD);
  $.ajax({
    type:'get', url:"/admin/course_infos/get_course_list?"+ transD,
    success: function(data) {
      if (data.error) {
        // console.log("wrong");
      } 
    }
  });
};

</script>
